package com.tiancai.config;

import com.tiancai.interceptor.JwtTokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    // 拦截器对象
    @Autowired
    private JwtTokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册自定义拦截器对象
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")  // 对所有路径进行拦截
                .excludePathPatterns(  // 排除不需要拦截的路径
                        "/swagger-ui/**",  // 排除 Swagger UI 页面
                        "/v3/api-docs/**",  // 排除 Swagger API 文档路径
                        "/swagger-resources/**", // 排除 Swagger 资源路径
                        "/webjars/**",  // 排除 webjars 静态资源路径
                        "/users/login",// 保持你原有的登录排除
                        "/users/sendEmail",
                        "/users/regist"
                );
    }
}
